<?php
/**
 * @Author: xuzhiyi
 * @Date:   2016-02-01 10:23:14
 * @Last Modified by:   xuzhiyi
 * @Last Modified time: 2016-02-29 16:49:25
 * ------------------------------------------------ *
 * 职员管理 *
 * ------------------------------------------------ */ 

namespace Admin\Controller;

class ManagersController extends CommonController {
	public function index(){
		if(IS_AJAX){
			switch(I('ajax')){
				case "workStatus":
				case "managerStatus":
					$status = D('managers')->editStatus(I('ajax'));
					$this->ajaxReturn($status);
					break;
				case "checkUser":				
					$user=D('managers')->where('loginName="'.I('loginName').'"')->find();				
					$this->ajaxReturn(!$user);
					break;

				
				case "addManager":
					$m=$this->upload();exit;
					
					if($m){
						$this->success('新职员添加成功','',true);
					}
					$this->error('新职员添加失败','',true);

					break;
				case "delManagers":
					$status = D('managers')->delManagers();
					$this->ajaxReturn($status);
					break;

				default:
					$manager =M('managers')->join('as a left join '.C("DB_PREFIX").'roles as b on a.managerRoleId=b.roleId')->field('a.*,b.roleName')->where('managerFlag!=-1')->select();
					$output['data']=$manager;
					$this->ajaxReturn($output);
			}
		}
		if(I('noAjax')=="addManagers"){
			
			$m = D('managers')->addManagers();
			if($m){
				
				echo "<script>parent.callback('新职员添加成功！',1)</script>";
				return;
			}		
			echo "<script>parent.callback('新职员添加失败！',0)</script>";
			return;
		}
		if(I('noAjax')=="editManagers"){
			$m = D('managers')->editManagers();
			if($m){
				
				echo "<script>parent.callback('职员修改成功！',1)</script>";
				return;
			}		
			echo "<script>parent.callback('职员修改失败！',0)</script>";
			return;
		}
		$roles=D('roles')->getRoles();
		$this->assign('roles',$roles);
		$this->display();
	}

	
}